package com.ssm.zhihu_ssm.controller;

import com.ssm.zhihu_ssm.entity.User;
import com.ssm.zhihu_ssm.entity.UserMessage;
import com.ssm.zhihu_ssm.service.UserMessageService;
import com.ssm.zhihu_ssm.service.UserService;
import com.ssm.zhihu_ssm.util.ReturnMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class UserMessageController {

    @Autowired
    private UserMessageService userMessageService;
    @Autowired
    private UserService userService;


    @RequestMapping("/findUserMessage")//得到用户所有个人信息
    @ResponseBody
    private Map<String, Object> findUserMessage(String phone) {
        int x = userService.findId(phone);

        User user = userMessageService.findUserMessage(x);
        Map<String, Object> map = ReturnMap.ReturnMapS(user);
        return map;

    }
    @RequestMapping("/getoneMessage")//得到用户所有个人信息
    @ResponseBody
    private Map<String, Object> findoneMessage(int id) {
        User user = userMessageService.findUserMessage(id);
        Map<String, Object> map = ReturnMap.ReturnMapS(user);
        return map;

    }

    @RequestMapping("/setUserMessage")//增加个人信息
    @ResponseBody
    private Map<String, Object> setUserMessage(String phone,String sex,String nickName,String dwell,String introduce,String answer,String article, String  email,String profession,String img) {
            int id = userService.findId(phone);
        UserMessage userMessage = new UserMessage(id,sex,nickName,dwell,introduce,email,answer,article,profession,img);
        boolean user = userMessageService.setUserMessage(userMessage);
        Map<String, Object> map = ReturnMap.ReturnMapS(user);
        return map;

    }

}
